$(window).load(function(){
	$.post("findBook.tushu", {"tag" : "","currentNum" : 1}, function(r) {
		creathtml(r);
	})
})
//分页ajax
 function ajaxSubmit(tag,currentNum){
	$.post("findBook.tushu",{"tag":tag,"currentNum":currentNum},function(r){
	 //动态创建分页的HTML
	creathtml(r);
	       	 });  		 
	       }
		
		
		
	function creathtml(r) {
		var obj=eval("("+r+")");
		var currentNum=obj.currentNum;
		var listPage=obj.listPage;
		var allPage=obj.allPage;
		//得到按钮
		var new_product=$("#new_product");
		var new_productin="";
		var pagination=$("#pagination");
		var paginationin="<a id='up' style='cursor:pointer'><<</a>";
		for(var i=1;i<=allPage;i++){
			paginationin+="<a id='pageNum' style='cursor:pointer'>"+i+"</a>";
		}
		paginationin+="<a id='next' style='cursor:pointer'>>></a>";
	 	$.each(listPage,function(index,obj){
			  new_productin+="<div class='new_prod_box'><a href='findBookProduct.tushu?bookId="+listPage[index].bookId+"'>"+listPage[index].bookName+
			  "</a><div class='new_prod_bg'><span class='new_icon'></span><a href='findBookProduct.tushu?bookId="+listPage[index].bookId+"'><img src='images/thumb3.gif' alt='' title='' class='thumb' border='0' /></a></div></div>"
		  
		});
		new_product.html(new_productin); 
		pagination.html(paginationin);
		
		//绑定事件
			$("#pageNum").click(function(){
				var pageNumValue=$("#pageNum").val;
				currentNum=pageNumValue;
				ajaxSubmit("",currentNum); 
			})
    	   //绑定下一页
    	   $("#next").click(function(){
    		   ajaxSubmit("next",currentNum);  		   
    	   });
    	   //绑定上一页
    	   	   $("#up").click(function(){
    	   		 ajaxSubmit("up",currentNum);		   
    	   });
	}